<HTML><HEAD><TITLE>+Condition *-> +Then ; +Else</TITLE>
</HEAD><BODY>[ <A HREF="index.html">Control</A> | <A HREF="../../index.html">Reference Manual</A> | <A HREF="../../fullindex.html">Alphabetic Index</A> ]
<H1>+Condition *-> +Then ; +Else</H1>
Soft-cut-conditional construct - succeeds if Then succeeds for
some solution of Condition, or if Condition fails and Else succeeds
<DL>
<DT><EM>Condition</EM></DT>
<DD>Atom or compound term.
</DD>
<DT><EM>Then</EM></DT>
<DD>Atom or compound term.
</DD>
<DT><EM>Else</EM></DT>
<DD>Atom or compound term.
</DD>
</DL>
<H2>Description</H2>
<P>   This construct is similar to the standard conditional construct
   <PRE>
   	Condition -> Then ; Else
   </PRE>
   except that it does not discard alternative solutions to Condition.
   This means that, on backtracking, alternative solutions to Condition
   are found, and the Then branch will be executed for each solution
   of the Condition (rather than just the first one).
   </P><P>
   This functionality is sometimes referred to as 'soft cut'. A soft cut
   is a cut that discards an alternative which is not the chronologically
   most recent one (the Else-alternative is older than the alternatives
   within Condition).
   </P><P>
   The operational semantics is as follows: if Condition succeeds, Then is executed,
   and on backtracking subsequent solutions of Condition and Then are returned, but
   Else is never executed.  Only if Condition has no solutions at all, Else is executed.
<P>
   Although it is allowed to use *-&gt;/2 without ;/2, this is of little
   use since (Condition *-&gt; Then) is the same as the simple conjunction (Condition , Then).
<P>
   Also note that a !/0 inside Condition only has a local effect in Condition.
   If a !/0 appears in Then or Else, it cuts through the whole construct.
<P>
   Since *-&gt;/2 and ;/2 have a lower precedence than ,/2, the whole construct
   should always be enclosed in parentheses:
    <PRE>
    ( Condition *-&gt;
        Then
    ;
        Else
    )
    </PRE>

<H3>Modules</H3>
This predicate is sensitive to its module context (tool predicate, see @/2).
<H3>Fail Conditions</H3>
Fails if Then fails for all solutions of Condition, or if Condition and Else both fail
<H3>Resatisfiable</H3>
Resatisfiable if Condition or Then are resatisfiable, or Condition is not satisfiable and Else is resatisfiable
<H3>Exceptions</H3>
<DL>
<DT><EM>(4) instantiation fault </EM>
<DD>One of the arguments is not instantiated.
<DT><EM>(5) type error </EM>
<DD>One of the arguments is neither an atom nor a compound term.
</DL>
<H2>Examples</H2>
<PRE>
	?- ( member(X,[1,2,3]) *-&gt; writeln(then(X)) ; writeln(else(X)) ).
	then(1)
	X = 1
	Yes (0.00s cpu, solution 1, maybe more) ? ;
	then(2)
	X = 2
	Yes (0.00s cpu, solution 2, maybe more) ? ;
	then(3)
	X = 3
	Yes (0.00s cpu, solution 3)


	?- X=4, ( member(X,[1,2,3]) *-&gt; writeln(then(X)) ; writeln(else(X)) ).
	else(4)
	Yes (0.00s cpu)

	?- ( member(X,[1,2]) *-&gt; member(Y,[a,b]) ; member(Y,[c,d]) ).
	X = 1
	Y = a
	Yes (0.00s cpu, solution 1, maybe more)
	X = 1
	Y = b
	Yes (0.02s cpu, solution 2, maybe more)
	X = 2
	Y = a
	Yes (0.02s cpu, solution 3, maybe more)
	X = 2
	Y = b
	Yes (0.03s cpu, solution 4)
</PRE>
<H2>See Also</H2>
<A HREF="../../kernel/control/-G-2.html">-> / 2</A>, <A HREF="../../kernel/control/O-2.html">; / 2</A>, <A HREF="../../kernel/control/I-0.html">! / 0</A>
</BODY></HTML>
